﻿using CKS2320.Common.Model;
using CKS2320.Common.Utils;
using CKS2320.Domain.DBEntity;
using CKS2320.Repository.Interface;
using log4net;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using NPOI.POIFS.Crypt.Dsig;
using NPOI.SS.Formula.Functions;
using Org.BouncyCastle.Asn1.Ocsp;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CKS2320.Repository
{
    public class ShapeRepository : IShapeRepository
    {
        public DBContext _dbCotext;
        
        public ShapeRepository(DBContext dbCotext, LogService logService)
        {
            _dbCotext = dbCotext;
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="shape"></param>
        /// <param name="detailList"></param>
        /// <returns></returns>
        public ResultReturn Add(Shape shape, List<Detectiondetail> detailList)
        {
            var shapeid = _dbCotext.Shapes.Add(shape);
            if (shapeid != null)
            {
                _dbCotext.Detectiondetails.AddRange(detailList);
            }
            var count = _dbCotext.SaveChanges();
            return MessageInfoUtils.Success(shape.Id);
        }

        public ResultReturn AddOP10(Op10coredata model)
        {
            var shapeid = _dbCotext.Op10coreDatas.Add(model);
            var count = _dbCotext.SaveChanges();
            return MessageInfoUtils.Success();
        }

        public IEnumerable<Shape> GetByPartCode(string partCode)
        {
            return _dbCotext.Shapes.Where(p => p.PartCode == partCode).ToList();
        }
    }
}
